using System;
using System.Collections.Generic;

namespace Project3D.my3D.Base
{

    public class myVector3D
    {
        public double dX, dY, dZ;

        public myVector3D() { }

        public myVector3D(double dx, double dy, double dz)
        {
            dX = dx;
            dY = dy;
            dZ = dz;
        }

        //Returns the dot product of v1 and v2.
        public static double operator *(myVector3D v1, myVector3D v2)
        {
            return myUtil.computeDotproduct(v1, v2);
        }

        public static myVector3D operator +(myVector3D v1, myVector3D v2)
        {
            return new myVector3D(v1.dX + v2.dX, v1.dY + v2.dY, v1.dZ + v2.dZ);
        }

        public static myVector3D operator /(myVector3D v1, double x)
        {
            v1.dX = v1.dX / x;
            v1.dY = v1.dY / x;
            v1.dZ = v1.dZ / x;

            return v1;
        }

        public static myVector3D CreateVector(myPoint3D p1, myPoint3D p2)
        {
            myVector3D vec = new myVector3D();

            vec.dX = p2.X - p1.X;
            vec.dX = p2.Y - p1.Y;
            vec.dX = p2.Z - p1.Z;

            return vec;
        }

        public double Length()
        {
            return Math.Sqrt(dX * dX + dY * dY + dZ * dZ);
        }

        public void normalize()
        {
            double _length = this.Length();

            if (_length != 0)
            {
                this.dX = dX / _length;
                this.dY = dY / _length;
                this.dZ = dZ / _length;
            }
        }

        public myVector3D Copy()
        {
            return new myVector3D(this.dX, this.dY, this.dZ);
        }

        public static double GetAngle(myVector3D v1, myVector3D v2)
        {
            myVector3D doProduct = new myVector3D();
            double dot = myUtil.computeDotproduct(v1, v2);

            double radian = Math.Acos(dot / (v1.Length() * v2.Length()));
            double degree = 180 * radian / Math.PI;
            return degree;
        }

    }

}
